package com.dingding.queue.queue.consumer;

import java.util.Properties;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;
import com.dingding.common.core.config.Constants;
import com.dingding.common.core.config.MessageQueueConfig;
import com.dingding.common.core.config.SystemConfig.TagsEnum;
import com.dingding.queue.queue.consumer.listener.AppointSpecialOrderListener;

@Component("appointSpecialOrderConsumer")
public class AppointSpecialOrderConsumer extends AbstractConsumer {

	Logger log = Logger.getLogger(this.getClass());

	@Resource(name = "appointSpecialOrderListener")
	private AppointSpecialOrderListener appointSpecialOrderListener;

	@Override
	public void intital() {
		startConsumer();
	}

	public void startConsumer() {
		try {
			log.info("正在订阅指派订单主题！");
			Properties properties = new Properties();
			properties.put(PropertyKeyConst.ConsumerId, MessageQueueConfig.getMESSAGE_QUEUE_APPOINT_CONSUMERID());
			properties.put(PropertyKeyConst.AccessKey, Constants.MESSAGE_QUEUE_ACCESSKEY);
			properties.put(PropertyKeyConst.SecretKey, Constants.MESSAGE_QUEUE_SERECTKEY);
			Consumer consumer = ONSFactory.createConsumer(properties);
			consumer.subscribe(MessageQueueConfig.getMESSAGE_QUEUE_TOPIC(), TagsEnum.APPOINT_SPECIAL_ORDER.toString(),
					appointSpecialOrderListener);
			consumer.start();
		} catch (Exception e) {
			log.error("订阅消息队列出现异常！ AppointSpecialOrderConsumer:intital()", e);
		}
	}
}
